package com.cg.design.depthdesign.adapter;

import com.cg.design.depthdesign.adapter.adapter.SquarePegAdapter;
import com.cg.design.depthdesign.adapter.round.RoundHole;
import com.cg.design.depthdesign.adapter.round.RoundPeg;
import com.cg.design.depthdesign.adapter.square.SquarePeg;

/**
 * 结构型模式：Adapter适配器模式测试类
 *
 * @author cg
 * @program LeetCode->AdapterTest
 * @create 2022-07-18 22:40
 **/
public class AdapterTest {

    public static void main(String[] args) {
        // Round fits round, no surprise.
        RoundHole hole = new RoundHole(5);
        RoundPeg rpeg = new RoundPeg(5);
        if (hole.fits(rpeg)) {
            System.out.println("Round peg r5 fits round hole r5.");
        }

        SquarePeg smallSqPeg = new SquarePeg(2);
        SquarePeg largeSqPeg = new SquarePeg(20);
        // hole.fits(smallSqPeg); // Won't compile.

        // Adapter solves the problem.
        SquarePegAdapter smallSqPegAdapter = new SquarePegAdapter(smallSqPeg);
        SquarePegAdapter largeSqPegAdapter = new SquarePegAdapter(largeSqPeg);
        if (hole.fits(smallSqPegAdapter)) {
            System.out.println("Square peg w2 fits round hole r5.");
        }
        if (!hole.fits(largeSqPegAdapter)) {
            System.out.println("Square peg w20 does not fit into round hole r5.");
        }
    }

}
